package file.sftp;

import com.jcraft.jsch.SftpException;

import java.io.File;
import java.io.InputStream;

/**
 * @author guoqf
 */
public class TsnFileServer {

    private final SFtpUtil sftpUtil;

    public TsnFileServer(String protocol, String ip, int port, String user, String pwd) {
        sftpUtil = new SFtpUtil(ip, port, user, pwd);
    }

    public TsnFileServer(String ip, int port, String user, String pwd) {
        System.out.printf("初始化文件服务器[ip=%s, port=%s, user=%s, pwd=%s]%n", ip, port, user, pwd);
        sftpUtil = new SFtpUtil(ip, port, user, pwd);
    }

    /**
     * 连接ftp服务器<br>
     *
     * @return 是否连接成功<br>
     */
    public boolean connect() {
       return sftpUtil.connect();
    }

    /**
     * 断开ftp服务器<br>
     *
     * @return 是否连接成功<br>
     */
    public boolean disconnect() {
        return sftpUtil.disconnect();

    }


    public InputStream download(String file, String dir) throws SftpException {
        return sftpUtil.download(file, dir);
    }


    public int upload(File localFile, String file, String dir) throws Exception {
        return sftpUtil.upload(localFile, dir, file);
    }

    public void remove(String file,String dir) throws SftpException{
       sftpUtil.remove(file, dir);
    }



}
